Skip to content

feat(langchain): add LangChain export adapter & runner with multi-provider support#16

Open
AJAmit17 wants to merge 14 commits intoopen-gitagent:mainfrom
AJAmit17:main
Open

feat(langchain): add LangChain export adapter & runner with multi-provider support#16
AJAmit17 wants to merge 14 commits intoopen-gitagent:mainfrom
AJAmit17:main

Conversation

@AJAmit17
Copy link
Contributor

@AJAmit17 AJAmit17 commented Mar 4, 2026

What

Add a LangChain export adapter and runner to gitagent. This allows exporting any gitagent agent definition to a runnable LangChain Python script, and executing it directly via the CLI.

Key features:

  • Provider support — auto-detects LLM provider from model name (gpt-*, o1-→ OpenAI; claude- → Anthropic). Unsupported models fail with a clear error message
  • Modern LangChain API — uses init_chat_model(), create_agent(), @tool decorator. No deprecated imports (AgentExecutor, ConversationBufferMemory, provider-specific classes)
  • Full manifest mapping — tools, sub-agents (mapped as delegate @tool functions), memory, knowledge docs (always_load), compliance constraints, delegation instructions, skills
  • Auto venv setup — runner creates a persistent venv at ~/.gitagent/langchain-venv, installs required packages automatically (Windows + Mac/Linux supported)
  • Provider-aware runner — checks correct env var (OPENAI_API_KEY or ANTHROPIC_API_KEY) before execution

Why

LangChain is one of the most widely used agent frameworks. Supporting it as an export target makes gitagent useful to a much larger audience and was explicitly listed as a wanted adapter in CONTRIBUTING.md.

Closes #2

How Tested

  • npm run build passes
  • gitagent validate passes on example agents
  • Manual testing on Windows 11, Node 22, Python 3.12:
    1. Exported all 5 examples via: gitagent export -f langchain -d examples/<name> -o <file>
    2. Python ast.parse() syntax validation passed on all 5 generated scripts
    3. End-to-end runs tested:
      • lyzr-agent with gpt-4.1 + OPENAI_API_KEY
      • full with claude-opus-4-6 + ANTHROPIC_API_KEY
  • CLI runner: gitagent run -d examples/minimal --adapter langchain
  • Prompt flag: gitagent run -d examples/lyzr-agent --adapter langchain -p "Summarize quantum computing"

Checklist

  • My code follows the existing style of this project
  • I have added/updated tests (if applicable)
  • I have updated documentation (if applicable)
  • I have read the CONTRIBUTING.md

@shreyas-lyzr
Copy link
Contributor

This is the oldest open PR (March 4). The LangChain adapter generates Python code using the Agents SDK. A few issues:

  1. Massive scope — 602 lines, touches README, multiple files. Should be split: adapter first, runner second.
  2. Runner modifies git.ts — adds LangChain auto-detection to the git runner, which is risky scope creep.
  3. No tests — all other recent adapter PRs include tests.
  4. Generated Python uses openai.agents — this is the OpenAI Agents SDK, not LangChain. The PR title says LangChain but the code generates OpenAI Agents SDK Python. Misleading.

Please clarify: is this a LangChain adapter or an OpenAI Agents SDK adapter? The generated code doesn't use LangChain at all.

AJAmit17 and others added 5 commits March 26, 2026 02:41
Full LangChain CLI adapter:
- Export: generates standalone Python scripts using LangChain agent framework
- Run: executes gitagent agents using LangChain runtime with venv management
- Multi-provider support: OpenAI (GPT-4, o1, o3) and Anthropic (Claude)
- Tool conversion: maps gitagent YAML tools to @tool decorated functions
- Sub-agent delegation: converts sub-agents to LangChain agent delegates
- System prompt: combines SOUL.md, RULES.md, skills
feat: add LangChain CLI adapter with export and run
@AJAmit17
Copy link
Contributor Author

This is the oldest open PR (March 4). The LangChain adapter generates Python code using the Agents SDK. A few issues:

  1. Massive scope — 602 lines, touches README, multiple files. Should be split: adapter first, runner second.
  2. Runner modifies git.ts — adds LangChain auto-detection to the git runner, which is risky scope creep.
  3. No tests — all other recent adapter PRs include tests.
  4. Generated Python uses openai.agents — this is the OpenAI Agents SDK, not LangChain. The PR title says LangChain but the code generates OpenAI Agents SDK Python. Misleading.

Please clarify: is this a LangChain adapter or an OpenAI Agents SDK adapter? The generated code doesn't use LangChain at all.

Hi @shreyas-lyzr, thanks for the detailed review!

Just to clarify — this is a LangChain adapter, not an OpenAI Agents SDK adapter. I believe there may have been a mismatch in how it was tested.

If you run:

npm run build
node dist/index.js export --format langchain -d examples/minimal -o test.py

the generated Python clearly uses LangChain APIs (create_agent, init_chat_model, @tool) with imports from langchain.*, not openai.agents.

Key points:

  • Tests are included and passing (langchain.test.ts)
  • The runner creates/reuses a virtualenv (gitagent-env) and installs langchain + langchain-openai before execution

Quick run (end-to-end)

npm run build
export OPENAI_API_KEY=your-key
node dist/index.js run -d examples/minimal --adapter langchain -p "Hello"

(Requires OPENAI_API_KEY to be set)

The confusion might come from using OpenAI models as a provider via LangChain, but the framework itself is fully LangChain-based.

Based on your feedback:

  • Moved LangChain-related changes out of git.ts into run.ts
  • Added tests
  • Included adapter docs for clarity

Do let me know if any improvements are needed to these changes I’ve made 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Adapter] LangChain export/runner

3 participants